<template>
  <ex-dialog width="1200px" class="ex-diolog" :title="title" :visible="visible" :close-on-click-modal="false"
    @closeDialog="handleClose">
    <div class="main" v-loading="loading">
      <el-form :model="ruleForm" :rules="rules" ref="ruleForm" :label-width="labelWidth" class="demo-ruleForm"
        :disabled="disabled">
        <el-form-item label="活动名称：" prop="name" :key="1">
          <el-input v-model="ruleForm.name" placeholder="请输入活动名称" :style="{width: inputWidth}" maxlength="50">
          </el-input>
        </el-form-item>
        <el-form-item label="券类型：" prop="couponType" :key="2">
          <el-select v-model="ruleForm.couponType" placeholder="请选择券类型" filterable :disabled="couponTypeDisabled"
            :style="{width: inputWidth}" @change="typeChange">
            <el-option v-for="item in couponTypeList" :key="item.id" :label="item.value" :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <!-- 平台 -->
        <template v-if="ruleForm.couponType==1">
          <div class="title_box">活动基础设置</div>
          <el-form-item label="活动图片：" prop="activityImg" ref="activityImgRef" :key="3">
            <ImageUploadMore :limit="1" :fileSize="20" @successImg="getactivityImg" :value="ruleForm.activityImg">
            </ImageUploadMore>
          </el-form-item>
          <el-form-item label="活动时间：" prop="dateTwo" ref="timeRef" :key="4">
            <el-date-picker v-model="ruleForm.dateTwo" type="datetimerange" value-format="yyyy-MM-dd HH"
              format="yyyy-MM-dd HH" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期"
              :clearable="false" @input="$forceUpdate()" :style="{width: inputWidth}">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="总库存：" prop="" required :key="5">
            <el-radio-group v-model="ruleForm.stockType" @change="stockTypeChange"
              :disabled="id != null && dialogStatus == 1?true:false">
              <el-form-item label="" prop="" :key="6">
                <el-radio :label="'1'">不限库存</el-radio>
              </el-form-item>
              <!-- 编辑 -->
              <el-form-item label="" prop="" v-if="id != null && dialogStatus == 1">
                <el-radio :label="'2'">
                  <span>限量</span>
                  <el-input v-model="ruleForm.newStock" :disabled="ruleForm.stockType=='1'?true:false"
                    placeholder="请输入增加库存数量" style="width: 300px;margin: 0 6px">
                  </el-input>
                </el-radio>
              </el-form-item>
              <!-- 新增、继续编辑 -->
              <el-form-item label="" prop="stock" ref="stockRef" :key="7" v-else>
                <el-radio :label="'2'">
                  <span>限量</span>
                  <el-input :disabled="ruleForm.stockType=='1'?true:false" v-model="ruleForm.stock" placeholder="请输入"
                    style="width: 300px;margin: 0 6px">
                  </el-input>
                </el-radio>
              </el-form-item>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="限购：" prop="" required :key="8">
            <el-radio-group v-model="ruleForm.buyType" @change="buyTypeChange">
              <el-form-item label="" prop="" :key="9">
                <el-radio :label="'1'">不限购买</el-radio>
              </el-form-item>
              <el-form-item label="" prop="limitAmount" ref="buyTypeRef" :key="10">
                <el-radio :label="'2'">
                  <span>限制购买</span>
                  <el-input :disabled="ruleForm.buyType=='1'?true:false" v-model="ruleForm.limitAmount"
                    placeholder="请输入" style="width: 274px;margin: 0 6px">
                  </el-input>
                </el-radio>
              </el-form-item>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="销售价格：" required :key="11">
            <el-form-item label="" prop="sellPrice">
              <el-input v-model="ruleForm.sellPrice" placeholder="请输入" :style="{width: inputWidth}">
              </el-input>
            </el-form-item>
            <!-- <el-input v-model="ruleForm.sellPrice" placeholder="请输入" :style="{width: inputWidth}">
          </el-input> -->
          </el-form-item>

          <!-- 积分抵扣 -->
          <template>
            <el-form-item label="积分抵扣：" prop="integralDiscountType" required :key="60">
              <el-switch v-model="ruleForm.integralDiscountType" :active-value="'2'" :inactive-value="'1'"
                active-text="开启" inactive-text="关闭">
              </el-switch>
            </el-form-item>
            <div style="padding: 0 86px" v-if="ruleForm.integralDiscountType=='2'">
              <el-form-item label="积分类型：" prop="integralType" :key="61">
                <el-select v-model="ruleForm.integralType" placeholder="请选择" filterable style="width: 330px">
                  <el-option v-for="item in integralTypeLs" :key="item.id" :label="item.value" :value="item.id">
                  </el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="可用数量：" required :key="62">
                <el-form-item label="" prop="integralUseAmount">
                  <el-input v-model="ruleForm.integralUseAmount" placeholder="请输入积分可用数量" style="width: 330px">
                  </el-input>
                </el-form-item>
              </el-form-item>
              <el-form-item label="抵扣金额：" required :key="63">
                <el-form-item label="" prop="integralDiscountMoney">
                  <el-input v-model="ruleForm.integralDiscountMoney" placeholder="请输入积分可抵扣金额" style="width: 330px">
                  </el-input>
                </el-form-item>
              </el-form-item>
              <el-form-item label="退款手续费：" required :key="64">
                <el-form-item label="" prop="integralRefundAmount">
                  <el-input v-model="ruleForm.integralRefundAmount" placeholder="请输入退款扣除积分数量" style="width: 330px">
                  </el-input>
                </el-form-item>
              </el-form-item>
            </div>
          </template>

          <!-- 到店产品设置 -->
          <div class="title_box">
            <span>到店产品设置</span>
            <el-button type="primary" @click="addInStoreProducts">新增</el-button>
            <!-- <el-button type="primary" plain v-if="dialogStatus!=2" @click="releaseInventory">释放库存</el-button> -->
          </div>
          <div class="in_store_products" v-for="(nav,commodityIndex) in ruleForm.commodityList"
            :key="100 + commodityIndex">
            <div class="in_store_products_box">
              <div class="el-icon-delete commodity_list_delete" v-if="dialogStatus==2&&commodityIndex!=0"
                @click="deleteCommodityLs(commodityIndex)"></div><!-- 删除 -->
              <el-form-item label="产品名称：" :prop="'commodityList.' + commodityIndex + '.couponName'"
                :rules="rules.couponName" ref="refOne" :key="12">
                <el-input v-model="nav.couponName" placeholder="请输入产品名称" :style="{width: inputWidth}" maxlength="50">
                </el-input>
              </el-form-item>
              <el-form-item label="产品图片：" :prop="'commodityList.' + commodityIndex + '.commodityImgList'"
                :rules="rules.commodityImgList" ref="commodityImgListRef" :key="13">
                <ImageUploadMore :limit="6" :fileSize="20" @successImg="getCommodityImgList($event,commodityIndex)"
                  :value="nav.commodityImgList">
                </ImageUploadMore>
              </el-form-item>
              <el-form-item label="销售原价：" required :key="14">
                <el-form-item label="" :prop="'commodityList.' + commodityIndex + '.originalPrice'"
                  :rules="rules.originalPrice">
                  <el-input v-model="nav.originalPrice" placeholder="请输入" :style="{width: inputWidth}">
                  </el-input>
                </el-form-item>
              </el-form-item>
              <el-form-item label="使用说明：" :prop="'commodityList.' + commodityIndex + '.useDetail'"
                :rules="rules.useDetail" ref="useDetailRef" :key="15">
                <!-- <el-input type="textarea" :autosize="{ minRows: 6, maxRows: 10}" v-model="nav.useDetail"
                  placeholder="请输入使用说明" :style="{width: inputWidth}" maxlength="1000" show-word-limit></el-input> -->
                  <WangEditor :value.sync="nav.useDetail" @change="useDetailChange($event,commodityIndex)" style="width:95%;" :lookStatus="disabled"></WangEditor>
              </el-form-item>
              <el-form-item label="核销方式：" :prop="'commodityList.' + commodityIndex + '.verificationType'"
                :rules="rules.verificationType" :key="170">
                <el-select v-model="nav.verificationType" placeholder="请选择" filterable :style="{width: inputWidth}"
                  :disabled="nav.id!=''&&dialogStatus!=2?true:false">
                  <el-option v-for="item in verificationTypeLs" :key="item.id" :label="item.value" :value="item.id">
                  </el-option>
                </el-select>
              </el-form-item>
              <!-- 超值到店 -->
              <template v-if="nav.verificationType==1">
                <el-form-item label="可核销店铺：" :prop="'commodityList.' + commodityIndex + '.shenyeShopIdList'"
                  :rules="rules.shenyeShopIdList" :key="16">
                  <el-select v-model="nav.shenyeShopIdList" multiple placeholder="请选择" filterable clearable
                    :style="{width: inputWidth}">
                    <el-option v-for="(item,index) in shopOption" :key="index" :label="item.value" :value="item.id" />
                  </el-select>
                </el-form-item>
                <el-form-item label="核销码来源：" :prop="'commodityList.' + commodityIndex + '.couponNoType'"
                  :rules="rules.couponNoType" :key="17">
                  <el-select v-model="nav.couponNoType" placeholder="请选择" filterable :style="{width: inputWidth}"
                    :disabled="nav.id!=''&&dialogStatus!=2?true:false">
                    <el-option v-for="item in couponNoTypeLs" :key="item.id" :label="item.value" :value="item.id">
                    </el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="权益名称：" :prop="'commodityList.' + commodityIndex + '.equityInventoryId'"
                  :rules="rules.equityInventoryId" :key="18" v-if="nav.couponNoType=='2'">
                  <el-select v-model="nav.equityInventoryId" placeholder="请选择" filterable :style="{width: inputWidth}"
                    :disabled="nav.id!=''&&dialogStatus!=2?true:false">
                    <el-option v-for="item in equityInventoryLs" :key="item.id" :label="item.value" :value="item.id">
                    </el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="二维码有效期：" prop="" required :key="19" v-if="nav.couponNoType=='1'">
                  <el-radio-group v-model="nav.couponValidityType"
                    @change="couponValidityTypeChange(nav,commodityIndex)">
                    <el-form-item label="" prop="">
                      <el-radio :label="'1'">不限时间</el-radio>
                    </el-form-item>
                    <template>
                      <!-- 校验用 -->
                      <el-form-item label="" :prop="'commodityList.' + commodityIndex + '.validityDay'"
                        :rules="rules.validityDay" ref="validityDayRef" :key="20" v-if="nav.couponValidityType=='2'">
                        <el-radio :label="'2'">
                          <span>购券之日起</span>
                          <el-input :disabled="nav.couponValidityType!='2'?true:false" v-model="nav.validityDay"
                            placeholder="请输入" style="width: 195px;margin: 0 6px 0px">
                          </el-input>
                          <span>天内有效</span>
                        </el-radio>
                      </el-form-item>
                      <!-- 不校验 -->
                      <el-form-item label="" ref="validityDayRef" :key="202" v-if="nav.couponValidityType!='2'">
                        <el-radio :label="'2'">
                          <span>购券之日起</span>
                          <el-input :disabled="nav.couponValidityType!='2'?true:false" v-model="nav.validityDay"
                            placeholder="请输入" style="width: 195px;margin: 0 6px 0px">
                          </el-input>
                          <span>天内有效</span>
                        </el-radio>
                      </el-form-item>
                    </template>
                    <template>
                      <!-- 校验用 -->
                      <el-form-item label="" :prop="'commodityList.' + commodityIndex + '.validityDate'"
                        :rules="rules.validityDate" :key="21" ref="validityDateRef" v-if="nav.couponValidityType=='3'">
                        <el-radio :label="'3'">
                          <span style="margin-right: 6px">生效时间段</span>
                          <el-date-picker v-model="nav.validityDate" type="datetimerange" value-format="yyyy-MM-dd"
                            style="margin: 20px 0 0px" format="yyyy-MM-dd" range-separator="至" start-placeholder="开始日期"
                            end-placeholder="结束日期" :clearable="false" @input="$forceUpdate()"
                            :style="{width: inputWidth}" :disabled="nav.couponValidityType!='3'?true:false">
                          </el-date-picker>
                        </el-radio>
                      </el-form-item>
                      <!-- 不校验 -->
                      <el-form-item label="" :key="210" ref="validityDateRef" v-if="nav.couponValidityType!='3'">
                        <el-radio :label="'3'">
                          <span style="margin-right: 6px">生效时间段</span>
                          <el-date-picker v-model="nav.validityDate" type="datetimerange" value-format="yyyy-MM-dd"
                            style="margin: 20px 0 0px" format="yyyy-MM-dd" range-separator="至" start-placeholder="开始日期"
                            end-placeholder="结束日期" :clearable="false" @input="$forceUpdate()"
                            :style="{width: inputWidth}" :disabled="nav.couponValidityType!='3'?true:false">
                          </el-date-picker>
                        </el-radio>
                      </el-form-item>
                    </template>
                  </el-radio-group>
                </el-form-item>
              </template>
              <!-- 椰椰邮差 -->
              <template v-if="nav.verificationType==2">
                <el-form-item label="可核销店铺：" :prop="'commodityList.' + commodityIndex + '.shenyeShopIdListvalue'"
                  :rules="rules.shenyeShopIdListvalue" :key="160">
                  <el-select v-model="nav.shenyeShopIdListvalue" placeholder="请选择" filterable clearable @input="$forceUpdate()"
                    :style="{width: inputWidth}">
                    <el-option v-for="(item,index) in shopOption" :key="index" :label="item.value" :value="item.id" />
                  </el-select>
                </el-form-item>
                <el-form-item label="有效期：" prop="" required :key="190">
                  <el-radio-group v-model="nav.couponValidityType"
                    @change="couponValidityTypeChange(nav,commodityIndex)">
                    <el-form-item label="" prop="">
                      <el-radio :label="'1'">不限时间</el-radio>
                    </el-form-item>
                    <template>
                      <!-- 校验用 -->
                      <el-form-item label="" :prop="'commodityList.' + commodityIndex + '.validityDay'"
                        :rules="rules.validityDay" ref="validityDayRef" :key="200" v-if="nav.couponValidityType=='2'">
                        <el-radio :label="'2'">
                          <span>购券之日起</span>
                          <el-input :disabled="nav.couponValidityType!='2'?true:false" v-model="nav.validityDay"
                            placeholder="请输入" style="width: 195px;margin: 0 6px 0px">
                          </el-input>
                          <span>天内有效</span>
                        </el-radio>
                      </el-form-item>
                      <!-- 不校验 -->
                      <el-form-item label="" ref="validityDayRef" :key="2020" v-if="nav.couponValidityType!='2'">
                        <el-radio :label="'2'">
                          <span>购券之日起</span>
                          <el-input :disabled="nav.couponValidityType!='2'?true:false" v-model="nav.validityDay"
                            placeholder="请输入" style="width: 195px;margin: 0 6px 0px">
                          </el-input>
                          <span>天内有效</span>
                        </el-radio>
                      </el-form-item>
                    </template>
                    <template>
                      <!-- 校验用 -->
                      <el-form-item label="" :prop="'commodityList.' + commodityIndex + '.validityDate'"
                        :rules="rules.validityDate" :key="210" ref="validityDateRef" v-if="nav.couponValidityType=='3'">
                        <el-radio :label="'3'">
                          <span style="margin-right: 6px">生效时间段</span>
                          <el-date-picker v-model="nav.validityDate" type="datetimerange" value-format="yyyy-MM-dd"
                            style="margin: 20px 0 0px" format="yyyy-MM-dd" range-separator="至" start-placeholder="开始日期"
                            end-placeholder="结束日期" :clearable="false" @input="$forceUpdate()"
                            :style="{width: inputWidth}" :disabled="nav.couponValidityType!='3'?true:false">
                          </el-date-picker>
                        </el-radio>
                      </el-form-item>
                      <!-- 不校验 -->
                      <el-form-item label="" :key="2100" ref="validityDateRef" v-if="nav.couponValidityType!='3'">
                        <el-radio :label="'3'">
                          <span style="margin-right: 6px">生效时间段</span>
                          <el-date-picker v-model="nav.validityDate" type="datetimerange" value-format="yyyy-MM-dd"
                            style="margin: 20px 0 0px" format="yyyy-MM-dd" range-separator="至" start-placeholder="开始日期"
                            end-placeholder="结束日期" :clearable="false" @input="$forceUpdate()"
                            :style="{width: inputWidth}" :disabled="nav.couponValidityType!='3'?true:false">
                          </el-date-picker>
                        </el-radio>
                      </el-form-item>
                    </template>
                  </el-radio-group>
                </el-form-item>
              </template>
            </div>
            <div class="move_box">
              <p class="el-icon-top" v-if="commodityIndex!=0&&dialogStatus!=3"
                @click="zIndexTop(ruleForm.commodityList,commodityIndex)">
              </p>
              <p class="el-icon-bottom" v-if="commodityIndex+1!=ruleForm.commodityList.length&&dialogStatus!=3"
                @click="zIndexDown(ruleForm.commodityList,commodityIndex)"></p>
            </div>
          </div>

          <!-- NFR产品设置 -->
          <div class="title_box">
            <span>NFR产品设置</span>
            <el-button type="primary" @click="addNfrLs">新增</el-button>
          </div>
          <div class="in_store_products" v-for="(nav,nfrIndex) in ruleForm.nfrlist" :key="200 + nfrIndex">
            <div class="in_store_products_box">
              <div class="el-icon-delete commodity_list_delete" @click="deleteNfrLs(nav,nfrIndex)"></div><!-- 删除 -->
              <el-form-item label="NFR卡功能：" :prop="'nfrlist.' + nfrIndex + '.nfrType'" :rules="rules.nfrType" :key="22">
                <el-select v-model="nav.nfrType" placeholder="请选择" filterable :style="{width: inputWidth}"
                  @change="(val) => changeNfrType(val,nfrIndex)" :disabled="nav.id!=''?true:false">
                  <el-option v-for="item in nfrType" :key="item.id" :label="item.value" :value="item.id">
                  </el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="选择NFR：" :prop="'nfrlist.' + nfrIndex + '.equityCardInventoryId'"
                :rules="rules.equityCardInventoryId" :key="23">
                <el-select v-model="nav.equityCardInventoryId" placeholder="请选择" filterable :style="{width: inputWidth}"
                  :disabled="nav.id!=''?true:false">
                  <el-option v-for="item in nav.equityCardInventoryLs" :key="item.id" :label="item.value"
                    :value="item.id">
                  </el-option>
                </el-select>
              </el-form-item>

              <el-form-item label="添加数量：" :key="25" v-if="nav.id!=''&&dialogStatus!=2">
                <el-form-item label="">
                  <el-input v-model="nav.nfrNewStock" placeholder="请输入" :style="{width: inputWidth}">
                  </el-input>
                  <span style="margin-left: 10px">原库存：{{nav.nfrStock}}</span>
                </el-form-item>
              </el-form-item>
              <el-form-item label="数量：" required :key="24" v-else>
                <el-form-item label="" :prop="'nfrlist.' + nfrIndex + '.nfrStock'" :rules="rules.nfrStock">
                  <el-input v-model="nav.nfrStock" placeholder="请输入" :style="{width: inputWidth}">
                  </el-input>
                </el-form-item>
              </el-form-item>
            </div>
            <div class="move_box">
              <p class="el-icon-top" v-if="nfrIndex!=0&&dialogStatus!=3" @click="zIndexTop(ruleForm.nfrlist,nfrIndex)">
              </p>
              <p class="el-icon-bottom" v-if="nfrIndex+1!=ruleForm.nfrlist.length&&dialogStatus!=3"
                @click="zIndexDown(ruleForm.nfrlist,nfrIndex)"></p>
            </div>
          </div>

          <!-- 资产激励设置 -->
          <div class="title_box">资产激励设置</div>
          <el-form-item label="行业：" prop="industryId" :key="26">
            <el-select v-model="ruleForm.industryId" placeholder="请选择行业" filterable :style="{width: inputWidth}"
              @change="industryChange">
              <el-option v-for="item in industryList" :key="item.id" :label="item.value" :value="item.id">
              </el-option>
            </el-select>
            <!-- <span style="margin-left: 10px;color:#1890ff" v-if="medalName!=''">{{medalName}}</span>
            <span style="margin-left: 10px;color: red" v-if="medalName==''">暂无勋章</span> -->
          </el-form-item>
          <template>
            <el-form-item label="消费奖励：" prop="awardType" ref="awardTypeRef" :key="27">
              <el-select v-model="ruleForm.awardType" placeholder="请选择" filterable :style="{width: inputWidth}">
                <el-option v-for="item in awardTypeList" :key="item.id" :label="item.value" :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
            <!-- <el-form-item label="" prop="awardAmount" ref="awardAmountRef" :key="21" v-if="ruleForm.awardType==1">
              <el-input v-model.number="ruleForm.awardAmount" placeholder="请输入赠送数量" :style="{width: inputWidth}">
              </el-input>
            </el-form-item> -->
          </template>
          <template>
            <el-form-item label="勋章奖励：" prop="medalAwardType" :key="28">
              <el-select v-model="ruleForm.medalAwardType" placeholder="请选择" filterable :style="{width: inputWidth}">
                <el-option v-for="item in medalAwardTypeList" :key="item.id" :label="item.value" :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="" prop="medalAwardAmount" ref="" :key="29" v-if="ruleForm.medalAwardType==1">
              <el-input v-model.number="ruleForm.medalAwardAmount" placeholder="填写获得贡献点" :style="{width: inputWidth}">
                <template slot="append">点</template>
              </el-input>
            </el-form-item>
          </template>
          <div class="title_box">奖池玩法设置</div>
          <el-form-item label="是否启用奖池玩法：" prop="jackpotType" required :key="30">
            <el-switch v-model="ruleForm.jackpotType" :active-value="'2'" :inactive-value="'1'" active-text="开启"
              inactive-text="关闭">
            </el-switch>
          </el-form-item>
          <template v-if="ruleForm.jackpotType=='2'">
            <el-form-item label="每单注入奖池金额：" prop="injectMoney" ref="" :key="31">
              <el-input v-model="ruleForm.injectMoney" placeholder="请输入" :style="{width: inputWidth}">
                <template slot="append">元</template>
              </el-input>
            </el-form-item>
            <el-form-item label="退款收取佣金金额：" prop="refundCommission" ref="" :key="32">
              <el-input v-model="ruleForm.refundCommission" placeholder="请输入" :style="{width: inputWidth}">
                <template slot="append">元</template>
              </el-input>
            </el-form-item>
            <el-form-item label="显示最高奖金：" prop="bonus" ref="" :key="33">
              <el-input v-model="ruleForm.bonus" placeholder="请输入" :style="{width: inputWidth}">
                <template slot="append">元</template>
              </el-input>
            </el-form-item>
            <el-form-item label="预计排行奖励：" prop="rankAward" ref="" :key="34">
              <el-input v-model="ruleForm.rankAward" placeholder="请输入" :style="{width: inputWidth}">
                <template slot="append">名</template>
              </el-input>
            </el-form-item>
            <el-form-item label="奖池资产类型：" prop="assetType" :key="35">
              <el-select v-model="ruleForm.assetType" placeholder="请选择" filterable :style="{width: inputWidth}">
                <el-option v-for="item in jackpotAssetTypeLs" :key="item.id" :label="item.value" :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="奖池规则：" prop="rule" ref="ruleImgRef" :key="36">
              <ImageUploadMore :limit="1" :fileSize="20" @successImg="getRuleImg" :value="ruleForm.rule">
              </ImageUploadMore>
            </el-form-item>
          </template>
          <el-form-item label="活动详情：" prop="" ref="" :key="37">
            <!-- <div class="richText">
              <Toolbar style="border-bottom: 1px solid #ccc" :editor="editor" :defaultConfig="toolbarConfig"
                :mode="mode" />
              <Editor style="height: 500px; overflow-y: hidden;" v-model="ruleForm.activityDetail"
                :defaultConfig="editorConfig" :mode="mode" @onCreated="onCreated" @onChange="onChange" />
            </div> -->
            <WangEditor :value.sync="ruleForm.activityDetail" :lookStatus="disabled"></WangEditor>
          </el-form-item>
        </template>

        <!-- 第三方 -->
        <template v-if="ruleForm.couponType==2">
          <el-form-item label="券名称：" prop="couponList" :key="38">
            <el-select v-model="ruleForm.couponList" multiple placeholder="请选择第三方商品" value-key="id" filterable clearable
              :style="{width: inputWidth}" @change="couponLsChange">
              <el-option v-for="(item,cIndex) in activitySelectList" :key="cIndex" :label="item.value" :value="item" />
            </el-select>
          </el-form-item>
          <el-form-item label="" prop="" :key="39">
            <el-table v-loading="loading" :data="tabList" stripe border>
              <el-table-column label="类型" align="center" class-name="small-padding fixed-width" width="150px">
                <template slot-scope="scope">
                  <el-input @input="inputClick" v-model="scope.row.commodityType" placeholder="请输入"
                    style="width: 130px">
                  </el-input>
                </template>
              </el-table-column>
              <el-table-column label="名称" align="center" class-name="small-padding fixed-width" width="150px">
                <template slot-scope="scope">
                  <el-input @input="inputClick" v-model="scope.row.couponName" placeholder="请输入" style="width: 130px">
                  </el-input>
                </template>
              </el-table-column>
              <el-table-column label="销售单价" align="center" class-name="small-padding fixed-width" width="150px">
                <template slot-scope="scope">
                  <el-input @input="inputClick" v-model="scope.row.sellPrice" placeholder="请输入" style="width: 130px">
                  </el-input>
                </template>
              </el-table-column>
              <el-table-column label="平台库存" align="center" class-name="small-padding fixed-width" width="150px">
                <template slot-scope="scope">
                  <el-input @input="inputClick" v-model="scope.row.platformStock" placeholder="请输入"
                    style="width: 130px">
                  </el-input>
                </template>
              </el-table-column>
              <el-table-column label="限购" align="center" class-name="small-padding fixed-width" width="150px">
                <template slot-scope="scope">
                  <el-input @input="inputClick" v-model="scope.row.limitAmount" placeholder="请输入" style="width: 130px">
                  </el-input>
                </template>
              </el-table-column>
              <el-table-column label="剩余数量" align="center" prop="surplusStock" :show-overflow-tooltip="true" />
              <el-table-column label="商品名称" align="center" prop="productName" :show-overflow-tooltip="true" />
              <el-table-column label="商品类型" align="center" prop="" :show-overflow-tooltip="true">
                <template slot-scope="scope">
                  <dict-tag :options="productTypeLs" :value="scope.row.productType" />
                </template>
              </el-table-column>
              <el-table-column label="面值" align="center" prop="faceValue" :show-overflow-tooltip="true" />
              <el-table-column label="单价" align="center" prop="purchasePrice" :show-overflow-tooltip="true" />
              <el-table-column label="库存" align="center" prop="" :show-overflow-tooltip="true">
                <template slot-scope="scope">
                  <dict-tag :options="stockStatusLs" :value="scope.row.stockStatus" />
                </template>
              </el-table-column>
              <el-table-column label="销售状态" align="center" prop="" :show-overflow-tooltip="true">
                <template slot-scope="scope">
                  <dict-tag :options="salesStatusLs" :value="scope.row.salesStatus" />
                </template>
              </el-table-column>
              <el-table-column label="商品详情" align="center" prop="details" :show-overflow-tooltip="true" />
              <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                  <el-button size="mini" type="text" @click="detele(scope)">删除</el-button>
                </template>
              </el-table-column>
            </el-table>
          </el-form-item>
          <el-form-item label="活动图片：" prop="activityImg" ref="" :key="40">
            <ImageUploadMore :limit="1" :fileSize="20" @successImg="getactivityImg" :value="ruleForm.activityImg">
            </ImageUploadMore>
          </el-form-item>
          <el-form-item label="活动时间：" prop="dateTwo" ref="timeRef" :key="41">
            <el-date-picker v-model="ruleForm.dateTwo" type="datetimerange" value-format="yyyy-MM-dd HH"
              format="yyyy-MM-dd HH" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期"
              :clearable="false" @input="$forceUpdate()" :style="{width: inputWidth}">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="第三方店铺：" prop="" :key="42">
            <el-select v-model="shopList" multiple placeholder="请选择" filterable clearable :style="{width: inputWidth}">
              <el-option v-for="(item,index) in shopOption" :key="index" :label="item.value" :value="item.id" />
            </el-select>
          </el-form-item>
          <el-form-item label="行业：" prop="industryId" :key="43">
            <el-select v-model="ruleForm.industryId" placeholder="请选择行业" filterable :style="{width: inputWidth}"
              @change="industryChange">
              <el-option v-for="item in industryList" :key="item.id" :label="item.value" :value="item.id">
              </el-option>
            </el-select>
            <!-- <span style="margin-left: 10px;color:#1890ff" v-if="medalName!=''">{{medalName}}</span>
            <span style="margin-left: 10px;color: red" v-if="medalName==''">暂无勋章</span> -->
          </el-form-item>
          <template>
            <el-form-item label="消费奖励：" prop="awardType" ref="awardTypeRef" :key="44">
              <el-select v-model="ruleForm.awardType" placeholder="请选择" filterable :style="{width: inputWidth}">
                <el-option v-for="item in awardTypeList" :key="item.id" :label="item.value" :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
            <!-- <el-form-item label="" prop="awardAmount" ref="awardAmountRef" :key="39" v-if="ruleForm.awardType==1">
              <el-input v-model.number="ruleForm.awardAmount" placeholder="请输入赠送数量" :style="{width: inputWidth}">
              </el-input>
            </el-form-item> -->
          </template>
          <template>
            <el-form-item label="勋章奖励：" prop="medalAwardType" :key="45">
              <el-select v-model="ruleForm.medalAwardType" placeholder="请选择" filterable :style="{width: inputWidth}">
                <el-option v-for="item in medalAwardTypeList" :key="item.id" :label="item.value" :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="" prop="medalAwardAmount" ref="" :key="46" v-if="ruleForm.medalAwardType==1">
              <el-input v-model.number="ruleForm.medalAwardAmount" placeholder="填写获得贡献点" :style="{width: inputWidth}">
                <template slot="append">点</template>
              </el-input>
            </el-form-item>
          </template>
          <el-form-item label="使用说明：" prop="useDetail" ref="useDetailRef" :key="47">
            <el-input type="textarea" :autosize="{ minRows: 6, maxRows: 10}" v-model="ruleForm.useDetail"
              placeholder="请输入使用说明" :style="{width: inputWidth}" maxlength="1000" show-word-limit></el-input>
          </el-form-item>
          <el-form-item label="是否启用奖池玩法：" prop="jackpotType" required :key="48">
            <el-switch v-model="ruleForm.jackpotType" :active-value="'2'" :inactive-value="'1'" active-text="开启"
              inactive-text="关闭">
            </el-switch>
          </el-form-item>
          <template v-if="ruleForm.jackpotType=='2'">
            <el-form-item label="每单注入奖池金额：" prop="injectMoney" ref="" :key="49">
              <el-input v-model="ruleForm.injectMoney" placeholder="请输入" :style="{width: inputWidth}">
                <template slot="append">元</template>
              </el-input>
            </el-form-item>
            <el-form-item label="显示最高奖金：" prop="bonus" ref="" :key="50">
              <el-input v-model="ruleForm.bonus" placeholder="请输入" :style="{width: inputWidth}">
                <template slot="append">元</template>
              </el-input>
            </el-form-item>
            <el-form-item label="奖池资产类型：" prop="assetType" :key="51">
              <el-select v-model="ruleForm.assetType" placeholder="请选择" filterable :style="{width: inputWidth}">
                <el-option v-for="item in jackpotAssetTypeLs" :key="item.id" :label="item.value" :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="奖池规则：" prop="rule" ref="ruleImgRef" :key="52">
              <ImageUploadMore :limit="1" :fileSize="20" @successImg="getRuleImg" :value="ruleForm.rule">
              </ImageUploadMore>
            </el-form-item>
          </template>
        </template>
      </el-form>
    </div>
    <div class="button_box" v-if="dialogStatus!=3">
      <el-button type="primary" :loading="AgreeLoading" @click="submitForm('ruleForm',5)" v-if="id==null">立即创建
      </el-button>
      <el-button type="primary" :loading="AgreeLoading" @click="editForm('ruleForm',5)" v-if="id!=null">保存提交</el-button>
      <el-button type="primary" :loading="cgLoading" @click="submitForm('ruleForm',1)"
        v-if="dialogStatus!=1&&dialogStatus!=3&&id==null">保存草稿</el-button>
      <el-button type="primary" :loading="cgLoading" @click="editForm('ruleForm',1)"
        v-if="dialogStatus!=1&&dialogStatus!=3&&id!=null">保存草稿</el-button>
      <el-button @click="handleClose">取消</el-button>
    </div>
  </ex-dialog>
</template>
<script>
  import Loading from "@/components/Loading/index";
  // api
  import {
    activitySelect,
    activityShopSelect,
    addShenyePunchActivity,
    shenyePunchDetail,
    updateShenyePunchActivity,
    activityIndustrySelect,
    inventorySelect,
    activityGetNFRSelect,
    nfrDeactivate,
    currentInventorySelect,
  } from "@/api/consumeMiningManagement/onlineClockingActivity";
  import '@wangeditor/editor/dist/css/style.css'
  import {
    Editor,
    Toolbar
  } from "@wangeditor/editor-for-vue";
  import WangEditor from '@/components/WangEditor'
  export default {
    components: {
      Loading,
      WangEditor,
      Editor,
      Toolbar
    },
    props: {
      visible: Boolean,
      id: String,
      dialogStatus: Number,
    },
    data() {
      var checkValidityDay = (rule, value, callback) => { //券有效期限制时间校验
        console.log(value)
        let regNumber = /^\+?[1-9]\d*$/; //大于0的正整数
        // console.log(value, this.ruleForm.couponValidityType)
        if (!value && this.ruleForm.commodityList[this.arrayIndex].couponValidityType == 2) {
          return callback(new Error('请输入数值'));
        } else if (regNumber.test(value) == false && this.ruleForm.commodityList[this.arrayIndex]
          .couponValidityType == 2) {
          return callback(new Error('请输入大于0正整数'));
        } else {
          return callback()
        }
      };
      var checkStock = (rule, value, callback) => { //总库存限制数量校验
        let regNumber = /^\+?[1-9]\d*$/; //大于0的正整数
        if (!value && this.ruleForm.stockType == 2) {
          return callback(new Error('请输入数值'));
        } else if (regNumber.test(value) == false && this.ruleForm.stockType == 2) {
          return callback(new Error('请输入大于0正整数'));
        } else {
          return callback()
        }
      };
      var checkLimitAmount = (rule, value, callback) => { //总库存限制数量校验
        let regNumber = /^\+?[1-9]\d*$/; //大于0的正整数
        if (!value && this.ruleForm.buyType == 2) {
          return callback(new Error('请输入数值'));
        } else if (regNumber.test(value) == false && this.ruleForm.buyType == 2) {
          return callback(new Error('请输入大于0正整数'));
        } else {
          return callback()
        }
      };
      var checkOriginalPrice = (rule, value, callback) => { //销售原价校验
        let regNumber = /(^[1-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/; //大于0的数值且最多保留两位小数的数值
        if (regNumber.test(value) == false || value == '0.00' || value == '0.0') {
          return callback(new Error('请填写大于0且最多保留两位小数的数值'));
        } else {
          return callback()
        }
      };
      var checkSellPrice = (rule, value, callback) => { //销售价格校验
        let regNumber = /(^[1-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/; //大于0的数值且最多保留两位小数的数值
        if (regNumber.test(value) == false || value == '0.00' || value == '0.0') {
          return callback(new Error('请填写大于0且最多保留两位小数的数值'));
        } else {
          return callback()
        }
      };
      var checkValidityDate = (rule, value, callback) => { //券有效期限制时间校验
        console.log(value, this.ruleForm.commodityList[this.arrayIndex].couponValidityType)
        // if (value.length == 0 && this.ruleForm.couponValidityType == 3) {
        //   return callback(new Error('请选择生效时间段'));
        // }
        if (value.length == 0 && this.ruleForm.commodityList[this.arrayIndex].couponValidityType == '3') {
          return callback(new Error('请选择生效时间段'));
        } else {
          return callback()
        }
      };
      var checkIntegralUseAmount = (rule, value, callback) => { //积分可用数量校验
        let regNumber = /(^[1-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/; //大于0的数值且最多保留两位小数的数值
        if (regNumber.test(value) == false || value == '0.00' || value == '0.0') {
          return callback(new Error('请填写大于0且最多保留两位小数的数值'));
        } else {
          return callback()
        }
      };
      var checkIntegralDiscountMoney = (rule, value, callback) => { //抵扣金额数量校验 (填写大于0的数字，可保留两位小数，需小于销售价格)
        let regNumber = /(^[1-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/; //大于0的数值且最多保留两位小数的数值
        if (regNumber.test(value) == false || value == '0.00' || value == '0.0') {
          return callback(new Error('请填写大于0且最多保留两位小数的数值'));
        } else if (Number(value) > Number(this.ruleForm.sellPrice)) {
          return callback(new Error('可抵扣金额量需小于等于销售价格'));
        } else {
          return callback()
        }
      };
      var checkIntegralRefundAmount = (rule, value, callback) => { //退款手续费 (填写大于等于0的数字，可保留两位小数，需小于可用数量)
        let regNumber = /(^[0-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/; //大于等于0的数值且最多保留两位小数的数值
        console.log(value, regNumber.test(value))
        if (regNumber.test(value) === false || value === '0.00' || value === '0.0') {
          return callback(new Error('请填写大于等于0且最多保留两位小数的数值'));
        } else if (Number(value) >= Number(this.ruleForm.integralUseAmount)) { 
          return callback(new Error('退款手续费需小于可用数量'));
        } else {
          return callback()
        }
      };
      return {
        labelWidth: '150px',
        inputWidth: '420px',
        title: '新增',
        loading: false,
        disabled: false,
        couponTypeDisabled: false,
        info: {},
        AgreeLoading: false, //按钮loading
        cgLoading: false,
        arrayIndex: 0, //数组下标
        couponTypeList: [], //券类型数组
        activitySelectList: [], //第三方券
        awardTypeList: [], //积分奖励类型
        productTypeLs: [], //商品类型
        salesStatusLs: [], //销售状态
        stockStatusLs: [], //库存状态
        integralTypeLs: [], //积分类型数组shenye_punch_activity_integral_type
        verificationTypeLs: [], //核销类型数组
        couponNoTypeLs: [{
          id: '1',
          value: '系统生成'
        }, {
          id: '2',
          value: '权益库存'
        }], //核销码来源下拉数组
        equityCardInventoryLs: [], //选择NFR下拉
        nfrType: [ //nfr卡功能下拉数组
          {
            id: '1',
            value: '权益NFR'
          },
          {
            id: '2',
            value: '勋章NFR'
          },
        ],
        equityInventoryLs: [], //权益库存下拉
        shopList: [],
        couponList: [],
        shopOption: [],
        medalAwardTypeList: [], //勋章类型
        industryList: [], //行业数组
        jackpotAssetTypeLs: [], //奖池资产类型数组
        punchActivityId: '', //活动id(编辑查询第三方券的时候传)
        dateTime: [new Date(2016, 9, 10, 8, 40), new Date(2016, 9, 10, 9, 40)],
        tabList: [],
        medalName: '', //勋章名称
        ruleForm: {
          couponName: '', //券名称（校验用）
          dateTwo: [], //活动时间（校验用）
          couponValidityType: '1', //券有效期类型（1：不限时间   2：限制时间）
          validityDay: '', //券有效期间隔天数 （校验用）
          originalPrice: '', //销售原价 （校验用）
          sellPrice: '', //销售价格 （校验用）
          couponList: [], //第三方券商品数组
          limitAmount: '', //	限购数量
          stock: '', //库存数量
          id: '', //	主键id 编辑时候传
          name: '', //活动名称
          couponType: '', //券类型 shenye_punch_activity_coupon_type
          activityDetailImg: '', //活动图片详情
          startTime: '', //活动开始时间
          endTime: '', //活动结束时间
          stockType: '1', //库存类型 第三方默认传1 shenye_punch_activity_stock_type
          buyType: '1', //
          newStock: '', //增加库存数量
          awardType: '', //奖励类型 shenye_punch_activity_award_type
          awardAmount: '0', //奖励数量
          useDetail: '', //使用说明
          status: '', //状态 shenye_punch_activity_status
          commodityList: [{
            id: '', //
            couponName: '', //券名称(平台券填写)
            couponValidityType: '1', //有效期类型 (平台券填写) shenye_punch_activity_coupon_validity_type
            validityDay: '', //间隔天数
            originalPrice: '', //销售原价（平台券填写）
            sellPrice: '', //销售价格(平台券和第三方都需要填写)
            couponId: '', //券id （第三方填写）
            commodityType: '', //商品类型（第三方券填写）
            limitAmount: '', //限购数量
            platformStock: '', //平台库存（第三方券填写）
            surplusStock: '', //剩余库存（第三方券填写）
            couponNoType: '', //券码来源类型 1 系统生成 2权益库存（平台券填写）
            equityInventoryId: '', //权益库存id（平台券填写）
            validityEndTime: '', //生效结束时间 yyyy-MM-dd（平台券填写）
            validityStartTime: '', //生效开始时间 yyyy-MM-dd（平台券填写）
            validityDate: [], //生效时间 (校验用)
            commodityImgList: [], //产品图片
            shenyeShopIdList: [], //可核销店铺id数组(平台)
            shenyeShopIdListvalue: '', //可核销店铺id数组(平台,椰椰邮差时使用)
            useDetail: '', //使用说明
            sort: '', //排序
            verificationType: '', //核销类型 shenye_punch_activity_verification_type
          }],
          nfrlist: [ //NFR产品设置
            // {
            //   id: '', //神椰打卡活动NFR信息id
            //   nfrType: '', //NFR卡功能类型 1权益NFR
            //   nfrStock: '', //NFR库存
            //   equityCardInventoryId: '', //NFR库存id
            //   nfrNewStock: '', //增加库存数量
            //   sort: '', //排序
            // }
          ],
          shenyeShopIdList: [],
          // commodityImgList: [], //产品图片
          activityImg: '', //活动图片
          industryId: '', //行业
          medalAwardType: '', //勋章奖励类型 1 奖励 2 不奖励
          medalAwardAmount: '', //勋章奖励点数量
          jackpotType: '1', //奖池类型 1关闭 2开启
          injectMoney: '', //每单注入奖池金额
          refundCommission: '', //退款收取佣金金额
          bonus: '', //显示最高奖金
          rankAward: '', //预计排行奖励(x名)
          assetType: '', //奖池资产类型 1椰分 2coco 3 现金 shenye_punch_activity_jackpot_asset_type
          activityDetail: '', //活动详情(富文本)
          rule: '', //奖池规则图片

          couponNoType: '', //券码来源类型 1 系统生成 2权益库存(校验用)
          equityInventoryId: '', //权益库存id(校验用)
          // validityDate: [], //生效时间 (校验用)
          xzList: [], //勋章NfR
          qyList: [], //权益NfR
          integralDiscountType: '1', //积分抵扣类型 1 关闭 2开启
          integralType: '', //积分类型 1 神椰Coco 2椰分 shenye_punch_activity_integral_type
          integralUseAmount: '', //积分使用数量
          integralDiscountMoney: '', //积分优惠金额
          integralRefundAmount: '', //积分退款手续费
        },
        rules: {
          name: [{
            required: true,
            message: "请输入活动名称",
            trigger: ['change', 'bulr'],
          }],
          couponType: [{
            required: true,
            message: "请选择券类型",
            trigger: ['change'],
          }],
          couponName: [{
            required: true,
            message: "请输入券名称",
            trigger: ['change', 'bulr'],
          }],
          activityImg: [{
            required: true,
            message: "请上传活动图片",
            trigger: ['change'],
          }],
          activityDetailImg: [{
            required: true,
            message: "请上传活动详情",
            trigger: ['change'],
          }],
          dateTwo: [{
            type: 'array',
            required: true,
            message: '请选择活动时间',
            trigger: 'change'
          }, ],
          validityDay: [{
              // validator: checkValidityDay,
              required: true,
              message: "请输入",
              trigger: ['change', 'bulr'],
            },
            {
              pattern: /^\+?[1-9]\d*$/,
              message: '请输入大于0正整数',
              trigger: ['change', 'bulr'],
            }
          ],
          stock: [{
            validator: checkStock,
            trigger: ['change', 'bulr'],
          }],
          limitAmount: [{
            validator: checkLimitAmount,
            trigger: ['change', 'bulr'],
          }],
          originalPrice: [{
            validator: checkOriginalPrice,
            trigger: ['change', 'bulr'],
          }],
          sellPrice: [{
            validator: checkSellPrice,
            trigger: ['change', 'bulr'],
          }],
          awardType: [{
            required: true,
            message: "请选择积分奖励类型",
            trigger: ['change'],
          }],
          awardAmount: [{
            required: true,
            message: "请输入赠送数量",
            trigger: ['change', 'bulr'],
          }],
          useDetail: [{
            required: true,
            message: "请输入使用说明",
            trigger: ['change', 'bulr'],
          }],
          couponList: [{
            type: 'array',
            required: true,
            message: '请选择第三方商品',
            trigger: 'change'
          }, ],
          commodityImgList: [{
            type: 'array',
            required: true,
            message: '请上传产品图片',
            trigger: 'change'
          }, ],
          industryId: [{
            required: true,
            message: "请选择行业",
            trigger: ['change', 'bulr'],
          }],
          medalAwardType: [{
            required: true,
            message: "请选择勋章奖励",
            trigger: ['change', 'bulr'],
          }],
          medalAwardAmount: [{
            required: true,
            message: "请填写获得贡献点",
            trigger: ['change', 'bulr'],
          }],
          injectMoney: [{
            required: true,
            message: "请填写每单注入奖池金额",
            trigger: ['change', 'bulr'],
          }],
          refundCommission: [{
            required: true,
            message: "请填写退款收取佣金金额",
            trigger: ['change', 'bulr'],
          }],
          bonus: [{
            required: true,
            message: "请填写显示最高奖金",
            trigger: ['change', 'bulr'],
          }],
          rankAward: [{
            required: true,
            message: "请填写预计排行奖励",
            trigger: ['change', 'bulr'],
          }],
          assetType: [{
            required: true,
            message: "请选择奖池资产类型",
            trigger: ['change', 'bulr'],
          }],
          rule: [{
            required: true,
            message: '请上传奖池规则图片',
            trigger: 'change'
          }, ],
          couponNoType: [{
            required: true,
            message: '请选择核销码来源',
            trigger: 'change'
          }, ],
          equityInventoryId: [{
            required: true,
            message: '请选择权益名称',
            trigger: 'change'
          }, ],
          validityDate: [{ //生效时间
            type: 'array',
            required: true,
            message: '请选择生效时间',
            trigger: 'change'
            // validator: checkValidityDate,
            // trigger: ['change', 'bulr'],
          }, ],
          shenyeShopIdList: [{ //核销店铺
            type: 'array',
            required: true,
            message: '请选择可核销店铺',
            trigger: 'change'
          }, ],
          nfrType: [{
            required: true,
            message: "请选择NFR卡功能",
            trigger: ['change', 'bulr'],
          }],
          equityCardInventoryId: [{
            required: true,
            message: "请选择NFR",
            trigger: ['change', 'bulr'],
          }],
          nfrStock: [{
            required: true,
            message: "请输入NFR库存",
            trigger: ['change', 'bulr'],
          }],
          integralType: [{
            required: true,
            message: "请选择积分类型",
            trigger: ['change', 'bulr'],
          }],
          integralUseAmount: [{
            validator: checkIntegralUseAmount,
            trigger: ['change', 'bulr'],
          }],
          integralDiscountMoney: [{
            validator: checkIntegralDiscountMoney,
            trigger: ['change', 'bulr'],
          }],
          integralRefundAmount: [{
            validator: checkIntegralRefundAmount,
            trigger: ['change', 'bulr'],
          }],
          verificationType: [{
            required: true,
            message: '请选择核销方式',
            trigger: 'change'
          }, ],
          shenyeShopIdListvalue: [{
            required: true,
            message: '请选择核销店铺',
            trigger: 'change'
          }, ],
        },
        // 富文本配置
        logoUploadUrlImg: process.env.VUE_APP_BASE_API + "/common/v1/upload", //图片接口
        videoUploadUrl: process.env.VUE_APP_BASE_API + "/common/v1/upload", //视频接口
        editor: null,
        html: "<p>hello&nbsp;world</p>",
        toolbarConfig: {
          // toolbarKeys: [ /* 显示哪些菜单，如何排序、分组 */ ],
          // excludeKeys: [ /* 隐藏哪些菜单 */ ],
          excludeKeys: ['group-video']
        },
        editorConfig: {

          placeholder: "请输入内容...",
          // autoFocus: false,
          // 所有的菜单配置，都要在 MENU_CONF 属性下
          MENU_CONF: {},
        },
        mode: 'default', // or 'simple'
      };
    },
    computed: {},
    async created() {
      this.getCouponTypeList()
      await this.getActivitySelect()
      this.getAwardTypeList()
      // this.getActivityShopSelect(1)
      this.getIntegralTypeLs()
      this.getProductType()
      this.getSalesStatusLs()
      this.getStockStatusLs()
      this.getProductType()
      this.getActivityIndustrySelect()
      this.getJackpotAssetType()
      this.getInventorySelect()
      this.getEquityCardInventoryLs(1)
      this.getEquityCardInventoryLs(2)
      this.getVerificationType()
      console.log(this.id, this.dialogStatus)
      if (this.id != null && this.dialogStatus == 1) {
        this.title = '编辑'
        this.couponTypeDisabled = true
        await this.getInfo()
      } else if (this.id != null && this.dialogStatus == 2) {
        this.title = '继续编辑'
        this.couponTypeDisabled = false
        await this.getInfo()
      } else if (this.id != null && this.dialogStatus == 3) {
        this.title = '查看'
        this.disabled = true
        await this.getInfo()
        console.log(this.disabled)
      }

    },
    mounted() {
      var _this = this
      // 配置上传图片
      var name = ''
      this.editorConfig.MENU_CONF['uploadImage'] = {
        server: _this.logoUploadUrlImg,
        // headers: _this.headers,
        fieldName: 'file',
        //    async customUpload(file, insertFn) {
        //        console.log(file)
        //     // file 即选中的文件
        //     // 自己实现上传，并得到图片 url alt href
        //     // 最后插入图片
        //     //   insertFn(url, alt, href)
        //     },
        onSuccess(file, res) {
          name = file.name
          // console.log(`${file.name} 上传成功`, res)
        },
        customInsert(res, insertFn) {
          console.log(res)
          insertFn(res.result.url, name, res.result.url)
        }
      }
      // 配置上传视频
      this.editorConfig.MENU_CONF['uploadVideo'] = {
        server: _this.videoUploadUrl,
        // headers: _this.headers,
        fieldName: 'file',
        maxFileSize: 500 * 1024 * 1024,
        //    async customUpload(file, insertFn) {
        //        console.log(file)
        //     // file 即选中的文件
        //     // 自己实现上传，并得到图片 url alt href
        //     // 最后插入图片
        //     //   insertFn(url, alt, href)
        //     },
        customInsert(res, insertFn) {
          // res 即服务端的返回结果
          // 从 res 中找到 url ，然后插入
          insertFn(res.result.url)
        },
      }
    },
    computed: {

    },
    methods: {
      // 富文本方法star
      onCreated(editor) {
        this.editor = Object.seal(editor); // 【注意】一定要用 Object.seal() 否则会报错
        console.log('this.editor', this.editor)
      },
      onChange(editor) {
        console.log("onChange", editor.getHtml()); // onChange 时获取编辑器最新内容
      },
      getEditorText() {
        const editor = this.editor;
        if (editor == null) return;

        console.log(editor.getText()); // 执行 editor API
      },
      printEditorHtml() {
        const editor = this.editor;
        if (editor == null) return;
        console.log(editor.getHtml()); // 执行 editor API
      }, // 富文本方法end

      //获取券类型字典
      getCouponTypeList() {
        var dictType = "shenye_punch_activity_coupon_type";
        this.$getSelectList(dictType)
          .then((res) => {
            this.couponTypeList = res.result[0].dictList;
          })
          .finally(() => {
            this.loading = false;
          });
      },
      //获取积分类型类型字典
      getIntegralTypeLs() {
        var dictType = "shenye_punch_activity_integral_type";
        this.$getSelectList(dictType)
          .then((res) => {
            this.integralTypeLs = res.result[0].dictList;
          })
          .finally(() => {
            this.loading = false;
          });
      },
      //获取积分奖励字典
      getAwardTypeList() {
        var dictType = "shenye_punch_activity_award_type";
        this.$getSelectList(dictType)
          .then((res) => {
            this.awardTypeList = res.result[0].dictList;
          })
          .finally(() => {
            this.loading = false;
          });
      },
      //获取商品类型字典
      getProductType() {
        var dictType = "shenye_third_commodity_product_type";
        this.$getSelectList(dictType)
          .then((res) => {
            this.productTypeLs = res.result[0].dictList;
          })
          .finally(() => {
            this.loading = false;
          });
      },
      //获取销售状态字典
      getSalesStatusLs() {
        var dictType = "shenye_third_commodity_sales_status";
        this.$getSelectList(dictType)
          .then((res) => {
            this.salesStatusLs = res.result[0].dictList;
          })
          .finally(() => {
            this.loading = false;
          });
      },
      //获取库存状态字典
      getStockStatusLs() {
        var dictType = "shenye_third_commodity_stock_status";
        this.$getSelectList(dictType)
          .then((res) => {
            this.stockStatusLs = res.result[0].dictList;
          })
          .finally(() => {
            this.loading = false;
          });
      },
      //获取核销类型字典
      getVerificationType() {
        var dictType = "shenye_punch_activity_verification_type";
        this.$getSelectList(dictType)
          .then((res) => {
            this.verificationTypeLs = res.result[0].dictList;
          })
          .finally(() => {
            this.loading = false;
          });
      },
      //获取第三方商品下拉框
      getActivitySelect() {
        return new Promise((resolve, reject) => {
          let data = {
            punchActivityId: this.id
          }
          activitySelect(data).then(res => {
            this.activitySelectList = res.result
            resolve()
          });
        })

      },
      //获取活动店铺下拉框 (type:店铺类型 1平台 2第三方)
      getActivityShopSelect(type) {
        let data = {
          type: type
        }
        activityShopSelect(data).then(res => {
          this.shopOption = res.result
        });
      },
      //获取勋章奖励类型字典
      getProductType() {
        var dictType = "shenye_punch_activity_jackpot_medal_award_type";
        this.$getSelectList(dictType)
          .then((res) => {
            this.medalAwardTypeList = res.result[0].dictList;
          })
          .finally(() => {
            this.loading = false;
          });
      },
      //获取活动行业下拉
      getActivityIndustrySelect() {
        activityIndustrySelect().then(res => {
          this.industryList = res.result
        });
      },
      //获取奖池资产类型字典
      getJackpotAssetType() {
        var dictType = "shenye_punch_activity_jackpot_asset_type";
        this.$getSelectList(dictType)
          .then((res) => {
            this.jackpotAssetTypeLs = res.result[0].dictList;
          })
          .finally(() => {
            this.loading = false;
          });
      },
      //获取权益库存下拉框
      getInventorySelect() {
        let data = {
          type: '1', //1:导入券码的权益
        }
        currentInventorySelect(data).then(res => {
          this.equityInventoryLs = res.result
        });
      },
      //获取nfr下拉
      getEquityCardInventoryLs(functionType) {
        var data = {
          functionType: functionType
        }
        activityGetNFRSelect(data).then(res => {
          // this.equityCardInventoryLs = res.result
          if (functionType == 1) {
            this.qyList = res.result
          } else {
            this.xzList = res.result
          }
          // console.log('this.qyList',this.qyList)
          // console.log('this.xzList',this.xzList)
        });
      },
      //选择NFR卡功能
      changeNfrType(e, index) {
        // xzList: [],//勋章NfR
        // qyList: [],//权益NfR
        if (this.ruleForm.nfrlist[index].equityCardInventoryId) {
          this.ruleForm.nfrlist[index].equityCardInventoryId = null
        }
        if (e == 1) {
          this.ruleForm.nfrlist[index].equityCardInventoryLs = this.qyList
        } else {
          this.ruleForm.nfrlist[index].equityCardInventoryLs = this.xzList
        }
        console.log('index', index)
        console.log('e', e)
      },
      //产品图片
      getCommodityImgList(e, index) {
        console.log(e, index)
        if (e != '') {
          this.ruleForm.commodityList[index].commodityImgList = e.split(",")
        } else {
          this.ruleForm.commodityList[index].commodityImgList = []
        }
        this.$refs['commodityImgListRef'][index].clearValidate();
      },
      //活动图片
      getactivityImg(e) {
        this.ruleForm.activityImg = e
        this.$refs['activityImgRef'].clearValidate();
      },
      // 获取商品图片
      getactivityDetailImg(e) {
        this.ruleForm.activityDetailImg = e
        this.$refs['imgRef'].clearValidate();
      },
      //奖池规则图片
      getRuleImg(e) {
        this.ruleForm.rule = e
        this.$refs['ruleImgRef'].clearValidate();
      },
      //商品类型选择
      typeChange(e) {
        this.shopList = []
        if (e == 1) {
          this.getActivityShopSelect(1)
        } else {
          this.getActivityShopSelect(2)
        }
      },
      //店铺行业选择
      industryChange(e) {
        console.log(e)
        this.industryList.forEach((item) => {
          if (e == item.id) {
            this.medalName = item.additionalValue
          }
        })
      },
      //券有效期选择
      couponValidityTypeChange(e, index) {
        this.arrayIndex = index
        console.log(e, this.arrayIndex)
        if (e.couponValidityType != 2) {
          // e.validityDay = ''
          this.$refs['validityDayRef'][index].clearValidate();
        } else if (e.couponValidityType != 3) {
          this.$refs['validityDateRef'][index].clearValidate();
        }
      },
      //库存类型选择
      stockTypeChange(e) {
        if (e == 1) {
          this.$refs['stockRef'].clearValidate();
        }
      },
      buyTypeChange(e) {
        if (e == 1) {
          this.$refs['buyTypeRef'].clearValidate();
          this.ruleForm.limitAmount = ''
        }
      },
      //第三方商品选择
      couponLsChange(e) {
        console.log(e)
        this.tabList = []
        let list = e
        list.forEach(item => {
          this.tabList = this.tabList.concat(item.data)
        });
        this.tabList.forEach((items, index) => {
          items.couponId = list[index].id
        })
        console.log(this.tabList)
      },
      detele(e) {
        console.log(e.$index)
        let index = e.$index
        this.tabList.splice(index, 1)
        this.ruleForm.couponList.splice(index, 1)
      },
      inputClick() { //修复input无法输入问题
        this.$forceUpdate()
      },
      //取消
      handleClose(formName) {
        this.$emit("update:visible", false);
      },
      /**
       * 数组元素交换位置
       * @param {array} arr 数组
       * @param {number} index1 添加项目的位置
       * @param {number} index2 删除项目的位置
       * index1和index2分别是两个数组的索引值，即是两个要交换元素位置的索引值，如1，5就是数组中下标为1和5的两个元素交换位置
       */
      swapArray(arr, index1, index2) {
        arr[index1] = arr.splice(index2, 1, arr[index1])[0];
        return arr;
      },
      //下移 将当前数组index索引与后面一个元素互换位置，向数组后面移动一位
      zIndexDown(arr, index) {
        if (index < 0) {
          console.log("索引值 为负值 不处理交换")
        } else if (index + 1 >= arr.length) {
          console.log("索引值+1 大于数组长度 导致数组越界 不处理交换")
        } else {
          this.swapArray(arr, index, index + 1);
        }
      },
      //上移 将当前数组index索引与前面一个元素互换位置，向数组前面移动一位
      zIndexTop(arr, index) {
        if (index == 0) {
          console.log("索引值 已经为0 左边没有值了 不处理交换")
        } else if (index >= arr.length) {
          console.log("索引值大于数组长度 导致数组越界 不处理交换")
        } else {
          this.swapArray(arr, index, index - 1);
        }
      },
      /** 新增到店产品设置 */
      addInStoreProducts() {
        this.ruleForm.commodityList.push({
          id: '', //
          couponName: '', //券名称(平台券填写)
          couponValidityType: '1', //有效期类型 (平台券填写) shenye_punch_activity_coupon_validity_type
          validityDay: '', //间隔天数
          originalPrice: '', //销售原价（平台券填写）
          sellPrice: '', //销售价格(平台券和第三方都需要填写)
          couponId: '', //券id （第三方填写）
          commodityType: '', //商品类型（第三方券填写）
          limitAmount: '', //限购数量
          platformStock: '', //平台库存（第三方券填写）
          surplusStock: '', //剩余库存（第三方券填写）
          couponNoType: '', //券码来源类型 1 系统生成 2权益库存（平台券填写）
          equityInventoryId: '', //权益库存id（平台券填写）
          validityEndTime: '', //生效结束时间 yyyy-MM-dd（平台券填写）
          validityStartTime: '', //生效开始时间 yyyy-MM-dd（平台券填写）
          validityDate: [], //生效时间 (校验用)
          commodityImgList: [], //产品图片
          shenyeShopIdList: [], //可核销店铺id数组(平台)
          useDetail: '', //使用说明
        })
      },
      deleteCommodityLs(index) { //删除到店产品设置
        this.ruleForm.commodityList.splice(index, 1);
      },
      /** 新增nfr产品设置 */
      addNfrLs() {
        this.ruleForm.nfrlist.push({
          id: '', //神椰打卡活动NFR信息id
          nfrType: '', //NFR卡功能类型 1权益NFR
          nfrStock: '', //NFR库存
          equityCardInventoryId: '', //NFR库存id
          nfrNewStock: '', //增加库存数量
          equityCardInventoryLs: []
        })
      },
      deleteNfrLs(item, index) { //删除nfr产品设置
        console.log(item)
        if (item.id != '' && this.dialogStatus != 2) {
          this.$confirm('删除释放锁定NFR库存，是否删除?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            let data = {
              nfrId: item.id,
              punchActivityId: this.id
            }
            nfrDeactivate(data).then(res => {
              this.$message({
                message: "操作成功",
                type: "success",
              });
              this.ruleForm.nfrlist.splice(index, 1);
            });
          }).catch(() => {});
        } else {
          this.ruleForm.nfrlist.splice(index, 1);
        }
      },
      getInfo() { //获取信息详情
        this.loading = true
        return new Promise((resolve, reject) => {

          shenyePunchDetail(this.id).then((res) => {
              this.loading = false
              // this.ruleForm = res.result
              let info = res.result
              this.ruleForm = {
                // couponName: info.commodityList[0].couponName, //券名称（校验用）
                dateTwo: [], //活动时间（校验用）
                // couponValidityType: info.commodityList[0].couponValidityType, //券有效期类型（1：不限时间   2：限制时间）
                // validityDay: info.commodityList[0].validityDay, //券有效期间隔天数 （校验用）
                // originalPrice: info.commodityList[0].originalPrice, //销售原价 （校验用）
                // sellPrice: info.commodityList[0].sellPrice, //销售价格 （校验用）
                // buyType: info.commodityList[0].buyType,
                // limitAmount: info.commodityList[0].limitAmount,
                sellPrice: info.sellPrice,
                buyType: info.buyType,
                limitAmount: info.limitAmount,
                couponList: [], //第三方券商品数组
                stock: info.stock, //库存数量
                // id: '', //	主键id 编辑时候传
                name: info.name, //活动名称
                couponType: info.couponType, //券类型 shenye_punch_activity_coupon_type
                activityImg: info.activityImg, //活动图片
                activityDetailImg: info.activityDetailImg, //活动图片详情
                startTime: info.startTime, //活动开始时间
                endTime: info.endTime, //活动结束时间
                stockType: info.stockType, //库存类型 第三方默认传1 shenye_punch_activity_stock_type
                awardType: info.awardType, //奖励类型 shenye_punch_activity_award_type
                awardAmount: info.awardAmount, //奖励数量
                useDetail: info.useDetail, //使用说明
                status: info.status, //状态 shenye_punch_activity_status
                commodityList: info.commodityList,
                shenyeShopIdList: info.shenyeShopIdList,
                commodityImgList: info.commodityImgList, //产品图片
                activityImg: info.activityImg, //活动图片
                industryId: info.industryId, //行业
                medalAwardType: info.medalAwardType, //勋章奖励类型 1 奖励 2 不奖励
                medalAwardAmount: info.medalAwardAmount, //勋章奖励点数量
                jackpotType: info.jackpotType, //奖池类型 1关闭 2开启
                injectMoney: info.injectMoney, //每单注入奖池金额
                refundCommission: info.refundCommission, //退款收取佣金金额
                bonus: info.bonus, //显示最高奖金
                rankAward: info.rankAward, //预计排行奖励(x名)
                assetType: info.assetType, //奖池资产类型 1椰分 2coco 3 现金 shenye_punch_activity_jackpot_asset_type
                activityDetail: info.activityDetail, //活动详情(富文本)
                rule: info.rule, //奖池规则图片
                // couponNoType: info.commodityList[0].couponNoType, //券码来源类型 1 系统生成 2权益库存
                // equityInventoryId: info.commodityList[0].equityInventoryId, //权益库存id
                // validityEndTime: info.commodityList[0].validityEndTime, //生效结束时间 yyyy-MM-dd
                // validityStartTime: info.commodityList[0].validityStartTime, //生效开始时间 yyyy-MM-dd
                // validityDate: [], //生效时间(校验用)
                nfrlist: info.nfrlist, //NFR产品设置
                integralDiscountType: info.integralDiscountType, //积分抵扣类型 1 关闭 2开启
                integralType: info.integralType, //积分类型 1 神椰Coco 2椰分 shenye_punch_activity_integral_type
                integralUseAmount: info.integralUseAmount, //积分使用数量
                integralDiscountMoney: info.integralDiscountMoney, //积分优惠金额
                integralRefundAmount: info.integralRefundAmount, //积分退款手续费
              }
              this.ruleForm.commodityList.forEach((item)=>{
                if(item.verificationType==2){
                  item.shenyeShopIdListvalue = item.shenyeShopIdList[0]
                }
              })
              this.ruleForm.nfrlist = this.ruleForm.nfrlist.map((item, index) => {
                if (item.nfrType == 1) {
                  item.equityCardInventoryLs = this.qyList
                } else if (item.nfrType == 2) {
                  item.equityCardInventoryLs = this.xzList
                }
                return item
              })
              console.log('this.ruleForm.nfrlist', this.ruleForm.nfrlist)
              // if (info.commodityList[0].validityStartTime != '') {
              //   this.ruleForm.validityDate[0] = info.commodityList[0].validityStartTime
              //   this.ruleForm.validityDate[1] = info.commodityList[0].validityEndTime
              // }
              if (info.industryId != '') {
                this.industryList.forEach((item) => {
                  if (info.industryId == item.id) {
                    this.medalName = item.additionalValue
                  }
                })
              }
              this.ruleForm.dateTwo[0] = res.result.startTime
              this.ruleForm.dateTwo[1] = res.result.endTime
              this.shopList = this.ruleForm.shenyeShopIdList
              if (this.ruleForm.couponType == 1) { //平台
                this.getActivityShopSelect(1)
                this.ruleForm.commodityList.forEach((item) => {
                  if (item.validityStartTime != '') {
                    item.validityDate = [item.validityStartTime, item.validityEndTime]
                  }
                })
              } else { //第三方
                this.getActivityShopSelect(2)
                let list = []
                console.log('activitySelectList', this.activitySelectList)
                console.log('info.commodityList', info.commodityList)
                this.activitySelectList.forEach((item) => {
                  info.commodityList.forEach((items) => {
                    if (item.id == items.couponId) {
                      console.log('呵呵呵', items.couponId)
                      list.push(item)
                    }
                  })
                })
                console.log('list', list)
                this.ruleForm.couponList = list

                list.forEach(item => {
                  this.tabList = this.tabList.concat(item.data)
                });

                this.tabList.forEach((items, index) => {
                  items.couponId = list[index].id
                  items.commodityType = info.commodityList[index].commodityType
                  items.couponName = info.commodityList[index].couponName
                  items.sellPrice = info.commodityList[index].sellPrice
                  items.platformStock = info.commodityList[index].platformStock
                  items.limitAmount = info.commodityList[index].limitAmount
                  items.surplusStock = info.commodityList[index].surplusStock
                })
              }

              console.log(this.ruleForm)
            })
            .finally(() => {
              this.loading = false;
            });
        })

      },
      submitForm(formName, status) {
        console.log(this.ruleForm)
        //创建确定
        this.$refs[formName].validate((valid) => {
          let isCheck = true
          let isStock = true
          let isAmount = true
          if (valid) {
            let regNumber = /(^[1-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/; //大于0的数值且最多保留两位小数的数值
            let regZheng = /^\+?[1-9]\d*$/
            let regZheng1 = /^[+]{0,1}(\d+)$/
            this.tabList.forEach(item => {
              if (regNumber.test(item.sellPrice) == false || item.sellPrice == '0.00' || item.sellPrice ==
                '0.0') {
                isCheck = false
              }
              if (item.platformStock) {
                if (regZheng1.test(item.platformStock) == false || item.platformStock == '0.00' || item
                  .platformStock == '0.0') {
                  isStock = false
                }
              }
              if (item.limitAmount) {
                if (regZheng.test(item.limitAmount) == false || item.limitAmount == '0.00' || item
                  .limitAmount == '0.0') {
                  isAmount = false
                }
              }
              console.log(regNumber.test(item.sellPrice), item.sellPrice)
            })
            if (!isCheck && this.ruleForm.couponType == 2) {
              this.$message({
                message: "销售单价需填写大于0且最多保留两位小数的数值",
                type: "error",
              });
              return
            }
            if (!isStock && this.ruleForm.couponType == 2) {
              this.$message({
                message: "平台库存需填写正整数",
                type: "error",
              });
              return
            }
            if (!isAmount && this.ruleForm.couponType == 2) {
              this.$message({
                message: "限购数量需填写大于0的整数",
                type: "error",
              });
              return
            }
            this.ruleForm.status = status
            this.ruleForm.startTime = this.ruleForm.dateTwo[0] + ':00:00'
            this.ruleForm.endTime = this.ruleForm.dateTwo[1] + ':00:00'
            this.ruleForm.shenyeShopIdList = this.shopList
            if (this.ruleForm.couponType == 1) { //平台
              console.log(222222, this.ruleForm.couponNoType)
              this.ruleForm.useDetail = this.ruleForm.commodityList[0].useDetail
              this.ruleForm.commodityList.forEach((item, index) => {
                item.sort = index
                if (item.validityDate != undefined && item.validityDate.length != 0) {
                  item.validityStartTime = item.validityDate[0]
                  item.validityEndTime = item.validityDate[1]
                }
                if (item.couponNoType == '2') {
                  item.couponValidityType = '1'
                }
                if (item.verificationType == 2) { //椰椰邮差
                  item.shenyeShopIdList = [item.shenyeShopIdListvalue]
                }
              })

              this.ruleForm.nfrlist.forEach((item, index) => {
                item.sort = index
              })
            } else { //第三方
              console.log(this.tabList)
              this.ruleForm.commodityList = this.tabList
            }
            if (this.ruleForm.awardType != 1) {
              this.ruleForm.awardAmount = 0
            }
            if (status == 1) {
              this.cgLoading = true
            } else {
              this.AgreeLoading = true
            }
            // console.log(this.ruleForm)
            // return
            var params = {
              ...this.ruleForm,
            };
            addShenyePunchActivity(params).then((res) => {
                this.$message({
                  message: "保存成功",
                  type: "success",
                });
                setTimeout(() => {
                  this.$emit('success')
                  this.handleClose()
                  // setTimeout(() => {
                  //   this.AgreeLoading = false
                  // }, 2000)
                  this.AgreeLoading = false
                  this.cgLoading = false
                }, 1000);
              })
              .catch(() => {
                this.AgreeLoading = false;
                this.cgLoading = false;
              });

          } else {
            console.log("error submit!!");
            return false;
          }
        });
      },
      editForm(formName, status) {
        //编辑确定
        console.log(this.ruleForm)
        this.$refs[formName].validate((valid) => {
          let isCheck = true
          let isStock = true
          let isAmount = true
          if (valid) {
            let regNumber = /(^[1-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/; //大于0的数值且最多保留两位小数的数值
            let regZheng = /^\+?[1-9]\d*$/
            let regZheng1 = /^[+]{0,1}(\d+)$/
            this.tabList.forEach(item => {
              if (regNumber.test(item.sellPrice) == false || item.sellPrice == '0.00' || item.sellPrice ==
                '0.0') {
                isCheck = false
              }
              if (item.platformStock) {
                if (regZheng1.test(item.platformStock) == false || item.platformStock == '0.00' || item
                  .platformStock == '0.0') {
                  isStock = false
                }
              }
              if (item.limitAmount) {
                if (regZheng.test(item.limitAmount) == false || item.limitAmount == '0.00' || item
                  .limitAmount == '0.0') {
                  isAmount = false
                }
              }
              // console.log(regNumber.test(item.sellPrice), item.sellPrice)
            })
            if (!isCheck) {
              this.$message({
                message: "销售单价需填写大于0且最多保留两位小数的数值",
                type: "error",
              });
              return
            }
            if (!isStock && this.ruleForm.couponType == 2) {
              this.$message({
                message: "平台库存需填写正整数",
                type: "error",
              });
              return
            }
            if (!isAmount && this.ruleForm.couponType == 2) {
              this.$message({
                message: "限购数量需填写大于0的整数",
                type: "error",
              });
              return
            }
            // this.ruleForm.status = status
            console.log('前++', this.ruleForm.status, status)
            if (this.ruleForm.status == 1 && status == 5) {
              this.ruleForm.status = 5
            } else {
              this.ruleForm.status = status
            }
            console.log('后++', this.ruleForm.status, status)
            // this.cgLoading = false
            // return

            this.ruleForm.startTime = this.ruleForm.dateTwo[0] + ':00:00'
            this.ruleForm.endTime = this.ruleForm.dateTwo[1] + ':00:00'
            this.ruleForm.shenyeShopIdList = this.shopList
            if (this.ruleForm.couponType == 1) { //平台
              this.ruleForm.useDetail = this.ruleForm.commodityList[0].useDetail
              this.ruleForm.commodityList.forEach((item, index) => {
                item.sort = index
                if (item.validityDate != undefined && item.validityDate.length != 0) {
                  item.validityStartTime = item.validityDate[0]
                  item.validityEndTime = item.validityDate[1]
                }
                if (item.couponNoType == '2') {
                  item.couponValidityType = '1'
                }
                if (item.verificationType == 2) { //椰椰邮差
                  item.shenyeShopIdList = [item.shenyeShopIdListvalue]
                }
              })
              this.ruleForm.nfrlist.forEach((item, index) => {
                item.sort = index
              })
              this.ruleForm.useDetail = this.ruleForm.commodityList[0].useDetail
            } else { //第三方
              console.log(this.tabList)
              this.ruleForm.commodityList = this.tabList
            }
            // console.log(this.ruleForm.awardType)
            if (this.ruleForm.awardType != 1) {
              this.ruleForm.awardAmount = 0
            }
            // this.AgreeLoading = true
            if (status == 1) {
              this.cgLoading = true
            } else {
              this.AgreeLoading = true
            }
            var params = {
              id: this.id,
              ...this.ruleForm,
            };
            // console.log(this.ruleForm.status,status,'++++')
            // return
            updateShenyePunchActivity(params).then((res) => {
                this.$message({
                  message: "修改成功",
                  type: "success",
                });
                setTimeout(() => {
                  this.$emit('success')
                  this.handleClose()
                  this.AgreeLoading = false
                  this.cgLoading = false
                }, 1000);
              })
              .catch(() => {
                this.AgreeLoading = false;
                this.cgLoading = false
              });

          } else {
            console.log("error submit!!");
            return false;
          }
        });
      },

      // 富文本框设置
      useDetailChange(e,index){
        if(e != ''){
          this.$refs.ruleForm.clearValidate(['commodityList.'+index+'.useDetail']);
        }
        // console.log(e,index)
        // console.log(this.ruleForm.)
      }
    },
  };

</script>
<style lang="scss" scoped>
  .ex-diolog {
    ::v-deep .ex--dialog--footer {
      border: none !important;
      padding: 0 !important;
    }

    ::v-deep .ex--dialog--main {
      padding: 10px 20px !important;
    }
  }

  .main {
    padding: 20px 20px;
  }

  .button_box {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px 0;
  }

  .richText {
    border: 1px solid #ccc;
    line-height: normal;
  }

  .title_box {
    font-size: 18px;
    color: #000;
    font-weight: bold;
    margin: 30px 0 20px;
    display: flex;
    align-items: center;
    border-top: 1px dashed #ccc;
    padding-top: 20px;
  }

  .title_box span {
    margin-right: 10px;
  }

  .in_store_products {
    display: flex;
  }

  .in_store_products_box {
    border: 1px solid #ddd;
    border-radius: 6px;
    margin-bottom: 20px;
    padding: 20px 0 10px;
    flex: 1;
    position: relative;
  }

  .commodity_list_delete {
    font-size: 30px;
    position: absolute;
    right: 30px;
    top: 30px;
    cursor: pointer;
    z-index: 2;
  }

  .commodity_list_delete:hover {
    color: red;
  }

  .move_box {
    display: flex;
    flex-direction: column;
    align-items: center;
    font-size: 40px;
    margin: 20px 0 0 30px;
  }

  .move_box p {
    margin-bottom: 20px;
    cursor: pointer;
  }

  .move_box p:hover {
    color: #1890FF;
  }

</style>
